package org.xy.yq.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.xy.yq.dao.IUserDao;
import org.xy.yq.entity.User;
import org.xy.yq.service.IUserService;

import java.util.List;
@Service("userServiceImpl")
public class UserServiceImpl implements IUserService {
    @Qualifier("userDaoImpl")
    @Autowired
    private IUserDao userDao;
    @Override
    public boolean register(User user) {
        boolean flag=true;
        try {
            userDao.register(user);//如果代码正常执行，表示注册成功
        }catch (Exception exception){
            flag = false;
        }
        return flag;
    }

    @Override
    public User login(String username, String password) {
        return userDao.login(username,password);
    }

    @Override
    public List<User> selectAll() {
        return userDao.selectAll();
    }

    @Override
    public boolean deleteById(int id) {
        boolean flag = true;
        try{
            userDao.deleteById(id);
        }catch (Exception e){
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean updateUser(User user) {
        boolean flag = true;
        try{
            userDao.updateUser(user);
        }catch (Exception exception){
            flag =false;
        }
        return flag;
    }
}
